<!--
 * @Desc:修改密码
 * @author cheegon
 * @date 2024/07/01  上午10:41
-->
<template>
  <el-dialog title="修改密码" v-dialog-drag :visible.sync="isShowPop">
    <el-form style="text-align: left" ref="formRef" :model="formData"
             :rules="formRules" label-width="150px">
      <el-form-item label="当前密码" prop="name">
        <el-input v-model="formData.password"  show-password></el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="name">
        <el-input v-model="formData.newPassword"  show-password></el-input>
      </el-form-item>
      <el-form-item label="确认密码密码" prop="name">
        <el-input v-model="formData.confirmPassword"  show-password></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="handleSubmit">提交</el-button>
    </div>
  </el-dialog>
</template>

<script>
import dialogMixin from '@/mixins/dialogMixin'
import { reqChangePassword } from '@/api/clientApi'

export default {
  name: "ChangePasswordDialog",
  components: {},
  props: [],
  mixins: [dialogMixin],
  data() {
    return {
      formData: {
        password: "",
        newPassword: '',
        confirmPassword: ''
      },
      formRules: {
        password: [
          { required: true, message: '当前密码不能为空', trigger: 'blur' }
        ],
        newPassword: [
          { required: true, message: '新密码不能为空', trigger: 'blur' }
        ],
        confirmPassword: [
          { required: true, message: '确认密码不能为空', trigger: 'blur' }
        ],
      },
    }
  },
  created() {
  },
  methods: {
    refresh() {
    },
    handleSubmit() {
      this.$refs.formRef.validate(valid => {
        if (!valid) return
        if (this.formData.newPassword != this.formData.confirmPassword) {
          this.$message.warning("新密码和确认密码不同")
          return
        }
        reqChangePassword(this.formData).then(data => {
          this.$message.success("修改成功")
          this.isShowPop = false
          this.onComplete()
        })
      })
    },
  }
}
</script>

<style lang="stylus" scoped>
.i_image {
  width 100px
  height 100px
}
</style>
